package com.kang.until;

import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.kang.pojo.PurchaseOrder;
import com.kang.pojo.PurchaseOrderItem;
import com.kang.pojo.ReturnOrderItem;
import com.kang.pojo.ReturnRequest;
import com.kang.pojo.ReturnRequestItem;
import com.kang.pojo.WarehouseOrder;
import com.kang.pojo.WarehousePoJo;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;

/**
 * 显示其他地方需要导出PDF的功能
 * @author zs
 *
 */
public class OtherRealizePDF {

	/**
	 * 字体
	 */
	public static BaseFont bf = null;
	/**
	 * 初始化字体
	 */
	static {
		try {
			bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 生成退货申请单PDF文件
	 * @param request
	 * @param list
	 * @return
	 */
	public static File buildReturnRequestPDF(ReturnRequest request,List<ReturnRequestItem> list) {
		//System.out.println("=============退货申请单详情==================");
		//PurchaseOrder Order = new PurchaseOrder();
		File pdfFile = new File(FileUtil.TEMP_PATH + "退货申请单" + request.getApplicationNo() + ".pdf");
		try {
			Font baseFont = new Font(bf, 14, Font.NORMAL);
			Document document = new Document(PageSize.A4, 10, 10, 10, 10);// 分别为文档的大小、左、右、上、下的页边距
			PdfWriter.getInstance(document, new FileOutputStream(pdfFile.getAbsolutePath()));
			document.open();
			Paragraph title = new Paragraph("退货申请单", new Font(bf, 16, Font.BOLD));
			title.setAlignment(1);// 居中对齐
			document.add(title);
			Table table = new Table(6);
			table.setBorderWidth(0);
			table.setBorderColor(new Color(0, 0, 0));
			table.setPadding(1);
			table.setSpacing(0);
			table.setWidth(100);

			Cell cell = new Cell(new Phrase("申请单号：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			cell = new Cell(new Phrase(request.getApplicationNo(), baseFont));
			cell.setColspan(3);
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);

			cell = new Cell(new Phrase("提交人：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			cell = new Cell(new Phrase(request.getSubmitterName(), baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);

			cell = new Cell(new Phrase("提交时间：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			//格式化时间
			SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD ");//设置日期格式
			String date2 = sdf.format(request.getCommitTime());
			cell = new Cell(new Phrase(date2.substring(0, 10), baseFont));
			cell.setColspan(2);
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			
			cell = new Cell(new Phrase("仓库：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			cell = new Cell(new Phrase(request.getWarehouseName(), baseFont));
			cell.setColspan(2);
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			
			cell = new Cell(new Phrase("退货说明：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			cell = new Cell(new Phrase(request.getReturnPolicy(), baseFont));
			cell.setColspan(2);
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			
			cell = new Cell(new Phrase("备注：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			cell = new Cell(new Phrase(request.getRemarks(), baseFont));
			cell.setColspan(2);
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);

			document.add(table);
			String[] tableHeader = { "物品批次", "退货申请ID", "物品ID", "状态", "退货数量" };
			table = PDFUtil.createTable("采购订单物品列表", baseFont, tableHeader, baseFont);
			String[] columns = { "batchNumber", "returnRequestID", "itemInformationID", "status", "number" };
			PDFUtil.setTableValue(table, columns, list, baseFont);
			document.add(table);
			document.add(new Paragraph(" ", baseFont));
			String str = "状态栏中 0:未提交，1:已提交，2:审核中，3:已通过，4:未通过";
			document.add(new Paragraph("说明："+str, baseFont));
			SimpleDateFormat sdf2 = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");//设置日期格式
			String date = sdf2.format(new Date());// new Date()为获取当前系统时间，也可使用当前时间戳
			document.add(new Paragraph(" ", baseFont));
			document.add(new Paragraph("打印时间："+date, baseFont));
			document.add(new Paragraph(" ", baseFont));
			document.add(new Paragraph("负责人签名：", baseFont));
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pdfFile;
	}
	
	
	/**
	 * 生成采购入库PDF文件
	 * @param request
	 * @param list
	 * @return
	 */
	/*public static File buildWarehouseOrderPDF(WarehouseOrder who,List<WarehousePoJo> list) {
		System.out.println("=============退货申请单详情==================");
		File pdfFile = new File(FileUtil.TEMP_PATH + "采购入库" + who.getWarehousenumber() + ".pdf");
		try {
			Font baseFont = new Font(bf, 14, Font.NORMAL);
			Document document = new Document(PageSize.A4, 10, 10, 10, 10);// 分别为文档的大小、左、右、上、下的页边距
			PdfWriter.getInstance(document, new FileOutputStream(pdfFile.getAbsolutePath()));
			document.open();
			Paragraph title = new Paragraph("采购入库", new Font(bf, 16, Font.BOLD));
			title.setAlignment(1);// 居中对齐
			document.add(title);
			Table table = new Table(6);
			table.setBorderWidth(0);
			table.setBorderColor(new Color(0, 0, 0));
			table.setPadding(1);
			table.setSpacing(0);
			table.setWidth(100);

			Cell cell = new Cell(new Phrase("入库单号：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			cell = new Cell(new Phrase(who.getWarehousenumber(), baseFont));
			cell.setColspan(3);
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);

			cell = new Cell(new Phrase("采购订单：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			cell = new Cell(new Phrase(who.getAddress(), baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);

			cell = new Cell(new Phrase("创建时间：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			//格式化时间
			SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD ");//设置日期格式
			String date2 = sdf.format(who.getCreatetime());
			cell = new Cell(new Phrase(date2.substring(0, 10), baseFont));
			cell.setColspan(2);
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			
			cell = new Cell(new Phrase("物品物料：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			//进行强制数据类型转换
			Integer a = who.getMaterialMaterial();
			String str = Integer.toString(a);
			cell = new Cell(new Phrase(str, baseFont));
			cell.setColspan(2);
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			
			cell = new Cell(new Phrase("入库说明：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			cell = new Cell(new Phrase(who.getCompany(), baseFont));
			cell.setColspan(2);
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			
			cell = new Cell(new Phrase("备注：", baseFont));
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);
			cell = new Cell(new Phrase(who.getRemarks(), baseFont));
			cell.setColspan(2);
			PDFUtil.setInfoCellStyle(cell);
			table.addCell(cell);

			document.add(table);
			String[] tableHeader = { "物品名称", "数量" ,"采购人" };
			table = PDFUtil.createTable("采购订单物品列表", baseFont, tableHeader, baseFont);
			String[] columns = { "chinesename", "number", "loginName" };
			PDFUtil.setTableValue(table, columns, list, baseFont);
			document.add(table);
			SimpleDateFormat sdf2 = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");//设置日期格式
			String date = sdf2.format(new Date());// new Date()为获取当前系统时间，也可使用当前时间戳
			document.add(new Paragraph(" ", baseFont));
			document.add(new Paragraph("打印时间："+date, baseFont));
			document.add(new Paragraph(" ", baseFont));
			document.add(new Paragraph("负责人签名：", baseFont));
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pdfFile;
	}*/
}
